﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace PrintBarcode.BUS
{
   
    class TStamp
    {
        UTLDB.UTLDB connect = new UTLDB.UTLDB();
        DataTable data = new DataTable();
        public TStamp() {
            DataColumn[] dc = new DataColumn[]{ 
                                new DataColumn("T1", Type.GetType("System.String")),
                                new DataColumn("WShell", Type.GetType("System.String")),
                                new DataColumn("NameUnit", Type.GetType("System.String")),
                                new DataColumn("WSeedL", Type.GetType("System.String")),
                                new DataColumn("WSeedM", Type.GetType("System.String")),
                                new DataColumn("PriceSeedL", Type.GetType("System.String")),
                                new DataColumn("PriceSeedM", Type.GetType("System.String")),
                                new DataColumn("V", Type.GetType("System.String")),  
                                new DataColumn("C", Type.GetType("System.String"))
            };
            data.Columns.AddRange(dc);

        }
        public DataTable GetStamp()
        {
            DataTable data = connect.GetDataByStoredProcedure("sp_mavach");
            return data;
        }

        public string FormatUnit(string str)
        {

            string result = "";
            string[] temp = str.Trim().Split('.');
            int len = temp[0].Length;
            switch (len)
            {
                case 1:
                    result = temp[0] + "L";
                    break;
                case 2:
                    result = temp[0].Substring(0, 1) + "P" + temp[0].Substring(1, 1) + "L";
                    break;
                case 3:
                    result = temp[0].Substring(0, 1) + "C" + temp[0].Substring(1, 1) + "P" + temp[0].Substring(2, 1) + "L";
                    break;
                case 4:
                    result = temp[0].Substring(0, 1) + "L" + temp[0].Substring(1, 1) + "C" + temp[0].Substring(2, 1) + "P" + temp[0].Substring(3, 1) + "L";
                    break;
            }
            if (temp.Length == 2)
                result += temp[1];
            return result;
        }
        public DataTable SetData()
        {
            DataRow r;
            int i = 0;
            DataTable dt = GetStamp();

            for (i = 0; i < dt.Rows.Count; i++)
            {
                r = data.NewRow();

                if (dt.Rows[i]["UnitID"].ToString() == "1")
                {
                    r["WShell"] = dt.Rows[i]["WSheed"].ToString() + "Gam";
                    r["C"] =String.Format("{0:0.00}", float.Parse(dt.Rows[i]["PriceShell"].ToString()) + float.Parse(dt.Rows[i]["giahattam"].ToString()) +float.Parse(dt.Rows[i]["giahatlon"].ToString()) + float.Parse(dt.Rows[i]["TienCong"].ToString()));
                }
                else { 
                    r["WShell"] = FormatUnit(dt.Rows[i]["WSheed"].ToString());
                    r["C"] = dt.Rows[i]["TienCong"].ToString();
            
                }
                r["WSeedL"] = FormatUnit(dt.Rows[i]["hatlon"].ToString());

                r["T1"] = "*" + dt.Rows[i]["Barcode"].ToString() + "*";
             
                r["NameUnit"] = dt.Rows[i]["NameUnit"].ToString();

                r["WSeedM"] = dt.Rows[i]["hattam"].ToString();
                r["PriceSeedL"] = dt.Rows[i]["giahatlon"].ToString();
                r["PriceSeedM"] = dt.Rows[i]["giahattam"].ToString();
                r["V"] =String.Format("{0:0.00}", float.Parse( dt.Rows[i]["PriceShell"].ToString()) + float.Parse( dt.Rows[i]["giahattam"].ToString()));

                data.Rows.Add(r);
            }
            return data;
        }
   
    
    }

}
